/*
  This is a simple example show the Heltec.LoRa sended data in OLED.

  The onboard OLED display is SSD1306 driver and I2C interface. In order to make the
  OLED correctly operation, you should output a high-low-high(1-0-1) signal by soft-
  ware to OLED's reset pin, the low-level signal at least 5ms.

  OLED pins to ESP32 GPIOs via this connecthin:
  OLED_SDA -- GPIO4
  OLED_SCL -- GPIO15
  OLED_RST -- GPIO16
  
  by Aaron.Lee from HelTec AutoMation, ChengDu, China
  成都惠利特自动化科技有限公司
  https://heltec.org
  
  this project also realess in GitHub:
  https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series
*/

#include "heltec.h"

#define BAND    915E6  //you can set band here directly,e.g. 868E6,915E6

String packSize = "--";
String packet ;

void cbk(int packetSize) {
  packet ="";
  packSize = String(packetSize,DEC);
  for (int i = 0; i < packetSize; i++) { packet += (char) LoRa.read(); }
  Serial.println(packet);
}

void setup()
{
  Heltec.begin(false /*DisplayEnable Enable*/, true /*Heltec.Heltec.Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
  Serial.begin(115200);
  Serial.setRxBufferSize(1024);
  LoRa.setSignalBandwidth(250E3);
}

void loop()
{ 
  if(Serial.available() > 0) {
    String data = "";
    data = Serial.readStringUntil('\n');
    
    // send packet
    LoRa.beginPacket(); 
    LoRa.print(data);
    LoRa.endPacket();
    // set radio back to receive mode
    LoRa.receive();
    
  } 
  int packetSize = LoRa.parsePacket();
  if (packetSize) { cbk(packetSize);  }
}
